<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link href="../../static/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet">
	<link rel="stylesheet" href="../../static/vui/css/vui.css">
	<script type="text/javascript" src="../../static/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../static/js/common.js"></script>
	<script type="text/javascript" src="../../static/vui/js/datagrid.js"></script>
	<script type="text/javascript" src="../../static/vui/js/treegrid.js"></script>

</head>
<body>

<div>
	<div style="height:513px;overflow: auto;width:182px;position: absolute;top:10px;left:10px;border:1px solid #e6e6e6;" id="treeOut">
		<div id="tree" style="margin:0px;"></div>
	</div>

	<div style="position: absolute;left:202px;top:1px;" id="formArea">
		<table class="table-top">
			<tr>
				<td>
					<input type="text" class="input" name="complex" placeholder="请输入供应商名称 或编码" autocomplete="off"/>
				</td>
				<td>
					<button class="button" id="query"><span>查询</span></button>
					<button class="button" id="reset"><span>重置</span></button>
				</td>
			</tr>
		</table>
	</div>

	<div style="position: absolute;left:202px;top:50px;">
		<div id="table"></div>
	</div>
</div>




<script>
    var params = app.getRequestParams();
    $(function(){
        $('#table').datagrid({
            simplePagination:true,
            width:580,limit:8,limits:[8],
            url:app.BASE_API_URL+'vendor/page',
            dblClickRow:selectRow,
            columns:[
                {field:'name',title:'供应商名称',width:160,fixed:true,formatter:function (row) {
                        return '<a href="javascript:void(0);" onclick="selectRow(this)" class="link">'+row.name+'</a>';
                    }},
                {field:'code',title:'供应商编码',width:80,fixed:true},
                {field:'contact',title:'联系人',width:80,fixed:true},
                {field:'contactPhone',title:'联系电话',width:160,fixed:true}
            ]
        });

        $('#tree').treegrid({
            width:180,
			head:false,
			root:-2,
            rootData:{id: "-1", parentId: "-2", name: "全部", logicalCode: "-1"},
            url:app.BASE_API_URL+'vendorType/select',
            columns:[
                {field:'name',title:'客户分类名称',width:180,fixed:true,formatter:function (row) {
                        return row.name.substr(row.name.lastIndexOf('/')+1);
                    }}
            ]
        });

        $('#query').click(function () {
            queryProduct();
        });

        $('#reset').click(function () {
            $('input[name="complex"]').val('');
        });

    });

    function selectRow(_this) {
        var row = $(_this).parent().parent().data();
        top.lastSelectVendorId = row.id;
        top.lastSelectVendorName = row.name;

        var searchId = params.queryId;
        if( !searchId ){
            searchId = params.searchId;
        }
        parent.$('#'+searchId).search("setValue",row.id,row.name);
        app.closeLastWindow();
    }

    function queryProduct(customerTypeLogicalCode) {
        var queryParams = app.serializeForm();
        queryParams.customerTypeLogicalCode = customerTypeLogicalCode;
        $("#table").datagrid("reload",queryParams);
    }
</script>
</body>
</html>